define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'distributionregion/index' + location.search,
                    add_url: 'distributionregion/add?ids=' + Config.ids,
                    edit_url: 'distributionregion/edit',
                    del_url: 'distributionregion/del',
                    multi_url: 'distributionregion/multi',
                    import_url: 'distributionregion/import',
                    table: 'distribution_region',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                queryParams: function (params) {
                    //这里可以追加搜索条件
                    var filter = JSON.parse(params.filter);
                    var op = JSON.parse(params.op);
                    //这里可以动态赋值，比如从URL中获取admin_id的值，filter.admin_id=Fast.api.query('admin_id');
                    filter.pid=Fast.api.query('ids');
                    op.pid = "=";
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'province', title: __('Title'), operate: 'LIKE'},
                        {field: 'city', title: __('Title'), operate: 'LIKE'},
                        {field: 'area', title: __('Title'), operate: 'LIKE'},
                        // {field: 'pid', title: __('Pid')},
                        {field: 'send_fee', title: __('Send_fee'), operate:false},
                        {field: 'weight', title: __('Weight'), operate:false},
                        {field: 'expense', title: __('Expense'), operate:false},
                        {field: 'day', title: __('Day')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
